'''

双集群gs_ddr相关公共函数

'''

from yat.test import macro

from testcase.utils.Logger import Logger

class DC_CommonSH:
    def __init__(self):
        self.log = Logger()

    def gs_ddr_start(self, env='', node, mode='', config='', disaster_type='', param=''):
        cmd = f'''source {env};
                gs_ddr -t start -m {mode} {config} {disaster_type} {param}'''
        self.log.info(cmd)
        res = node.sh(cmd).result()
        return res

    def gs_ddr_stop(self, env='', node, config='', param=''):
        cmd = f'''source {env};
                gs_ddr -t stop {config} {param}'''
        self.log.info(cmd)
        res = node.sh(cmd).result()
        return res

    def gs_ddr_failover(self, env='', node, param=''):
        cmd = f'''source {env};
                gs_ddr -t failover {param}'''
        self.log.info(cmd)
        res = node.sh(cmd).result()
        return res

    def gs_ddr_switchover(self, env='', node, mode='', param=''):
        cmd = f'''source {env};
                gs_ddr -t switchover -m {mode} {param}'''
        self.log.info(cmd)
        res = node.sh(cmd).result()
        return res

    def gs_ddr_query(self, env='', node, param=''):
        cmd = f'''source {env};
                gs_ddr -t query {param}'''
        self.log.info(cmd)
        res = node.sh(cmd).result()
        return res